package com.tywh.utils;

import java.util.Arrays;

/**
 * @ClassName GetAccesstoken
 * @Description TODO
 * @Author xhx
 * @Date 2019/7/29 12:22
 * @Version 1.0
 */
public class GetToken {

    public static String GetAccesstoken(String appid, String timestamp, String nonce, String appsecret) {

        //拼接成数组
        String[] input = {appid.toLowerCase(), appsecret.toLowerCase(), timestamp.toLowerCase(), nonce.toLowerCase()};
        //排序（按照ascii码从小到大）
        Arrays.sort(input);

        String tmpStr = "";
        for (int i = 0; i < input.length; i++) {
            tmpStr = tmpStr + input[i];
        }
        System.out.println("拼接字符串：" + tmpStr);
        //MD5加密
        tmpStr = MD5Util.MD5Encode(tmpStr, "utf8");
        tmpStr = tmpStr.toLowerCase();

        System.out.println("MD5后字符串：" + tmpStr);
        return tmpStr;
    }

}
